<?php
include_once("codelibrary/inc/variables.php");
function query($query,$extra="")
{
	$result = mysql_query($query) or die("Query execution error : ".mysql_error()."<br> Query : $query <br> Query Type : $extra");
	return $result;
}

function createCustomer($obj) {
	$status = "1";
	$fields = array('firstname','lastname','address','city','state','zipcode','dayphone','eveningphone','email','cellphone','username','password','business_id','status');
	$username = $obj['email'];
	foreach($fields as $f) {
		if($obj[$f]!='') {
			$field = $field."$f,";
			$values = $values."'$obj[$f]',";
		} elseif($$f!='') {
			$field = $field."$f,";
			$values = $values."'".$$f."',";
		}
	}
	$field = substr($field,0,strlen($field)-1);
	$values = substr($values,0,strlen($values)-1);
		
	$query = "insert into customer_info($field) values($values)";
	if(query($query)) {
		return mysql_insert_id();
	}

}

$email = $_REQUEST['email'];
$query = "select count(*) as count from customer_info where email='$email'";
$res = query($query);
$row = mysql_fetch_object($res);
if($row->count > 0) {
	header("location:customer-register.php?business_id=".$_REQUEST['business_id']."&logerr=exists");
} else {
	createCustomer($_REQUEST);
	header("location:customer-login.php?business_id=".$_REQUEST['business_id']."&logerr=success");
}

?>
